package com.itheima.d1_set;

import java.util.Objects;

//1.基于Demo04的需求，实现Comparable接口
public class Teacher implements Comparable<Teacher> {
    @Override
    public int compareTo(Teacher o) {
        //2.给TreeSet集合的底层红黑树结构制定排序规则！（红黑树结构，小的放左边，大的放右边，一样的不存！）

        //3.需求是根据年龄排序，获取两个Teacher对象的年龄
        int age1 = this.getAge();
        int age2 = o.getAge();

        //4.获取两个年龄的比较的整数结果
        int result = age1 - age2;

        //5.需求改进：如果年龄相同，就根据身高降序排序
        double height1 = this.getHeight();
        double height2 = o.getHeight();
        if (result == 0) {
            //条件成立，说明两个Teacher对象的年龄相同，此时result要根据身高计算
            result = Double.compare(height2, height1);
        }

        //6.返回result
        return result;
    }

    private String name;
    private int age;
    private double height;

    public Teacher() {
    }

    public Teacher(String name, int age, double height) {
        this.name = name;
        this.age = age;
        this.height = height;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public double getHeight() {
        return height;
    }

    public void setHeight(double height) {
        this.height = height;
    }

    @Override
    public String toString() {
        return "Teacher{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", height=" + height +
                '}';
    }

}
